1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy
4 : externaltools/classes/class.externaltool.inc.php
5 : - Modulgruppe: ExternalTools
6 : - Beschreibung:
7 : - Version: 0.1 23/04/05
8 : - Autor(en): Christian Gerhardt <case42@gmx.net>
9 : +---------------------------------------------------------------------------+
10 : This program is free software; you can redistribute it and/or
11 : modify it under the terms of the GNU General Public License
12 : as published by the Free Software Foundation; either version 2
13 : of the License, or any later version.
14 : +---------------------------------------------------------------------------+
15 : This program is distributed in the hope that it will be useful,
16 : but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : GNU General Public License for more details.
19 : You should have received a copy of the GNU General Public License
20 : along with this program; if not, write to the Free Software
21 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 : +--------------------------------------------------------------------------*/
23 : /**
24 : * Diese Datei enthällt die Klasse ExternalTool
25 : * @package eStudy.ExternalTools
26 : * @version 0.1 23/04/05
27 : * @author Christian Gerhardt <case42@gmx.net>
28 : */
29 :
30 : /**
31 : * Path to Root falls nicht gesetzt
32 : */
33 1 : if (!defined('PATH_TO_ROOT'))
34 1 : define("PATH_TO_ROOT", "../../");
35 :
36 : /***/
37 1 : require_once ("defines.inc.php");
38 :
39 : /**Für den Zugriff auf XPWeb*/
40 1 : require_once ("class.xpwebinfo.inc.php");
41 :
42 : /**Für den Zugriff auf Mantis*/
43 1 : require_once ("class.mantisinfo.inc.php");
44 :
45 : /**Für den Zugriff auf Mediawiki*/
46 1 : require_once ("class.mediawikiinfo.inc.php");
47 :
48 : /**Für den Zugriff auf Chat*/
49 1 : require_once ("class.chatinfo.inc.php");
50 :
51 : /**Für den Zugriff auf WordPress*/
52 1 : require_once ("class.wordpressinfo.inc.php");
53 :
54 1 : require_once ("class.estudyinfo.inc.php");
55 : /**
56 : *
57 : * @package eStudy.ExternalTools
58 : * @version 0.1 23/04/05
59 : * @author Christian Gerhardt <case42@gmx.net>
60 : */
61 1 : class ExternalTool {
62 : /**
63 : * Die ID des Tools.
64 : * @access private
65 : * @var integer
66 : */
67 : public $id;
68 : /**
69 : * Die Bezeichnung des Tools.
70 : * @access public
71 : * @var string
72 : */
73 : public $name;
74 : /**
75 : * Die URL des Tools.
76 : * @access public
77 : * @var string
78 : */
79 : public $url;
80 : /**
81 : * Die URL eines Logos für das Tool.
82 : * @access public
83 : * @var string
84 : */
85 : public $logo;
86 : /**
87 : * Ein Array mit allen verfügbaren ToolsInfos.
88 : * [Tooltype] => [ToolInfo-Objekt]
89 : * @access private
90 : * @var mixed
91 : */
92 : public $tools;
93 : /**
94 : * Der Typ des Tools.
95 : * Bezieht sich direkt auf den ToolsInfo-Typ.
96 : * @access private
97 : * @var string
98 : */
99 : public $type;
100 : /**
101 : *
102 : * @access public
103 : * @var integer
104 : */
105 : public $description;
106 : /**
107 : *
108 : * @access public
109 : * @var integer
110 : */
111 : public $registrationRequired = false;
112 : /**
113 : *
114 : * @access private
115 : * @var integer
116 : */
117 : public $userSignupSettings;
118 : /**
119 : *
120 : * @access public
121 : * @var integer
122 : */
123 : public $userRegisterStatus;
124 : /**
125 : *
126 : * @access public
127 : * @var integer
128 : */
129 : public $options;
130 : /**
131 : *
132 : * @access public
133 : * @var integer
134 : */
135 : public $toolOptions;
136 : /**
137 : *
138 : * @access public
139 : * @var integer
140 : */
141 : public $showInOwnWindow;
142 : /**
143 : * Erzeugt ein neues ExternalTool-Objekt.
144 : * @param integer $id - die id des tools
145 : */
146 : public function ExternalTool($toolDataArray) {
147 0 : $this->id = (int)$toolDataArray['ID'];
148 0 : $this->name = $toolDataArray['name'];
149 0 : $this->url = $toolDataArray['url'];
150 0 : $this->logo = isset($toolDataArray['logo']) ? $toolDataArray['logo'] : "";
151 0 : $this->type = $toolDataArray['type'];
152 0 : $this->description = isset($toolDataArray['description']) ? $toolDataArray['description'] : "";
153 0 : $this->options = isset($toolDataArray['options']) ? (int)$toolDataArray['options'] : 0;
154 0 : $this->showInOwnWindow = isset($toolDataArray['openInAnotherWindow']) ? (bool)$toolDataArray['openInAnotherWindow'] : false;
155 0 : $this->toolOptions = isset($toolDataArray['toolOptions']) && !is_numeric($toolDataArray['toolOptions']) ? unserialize(stripslashes($toolDataArray['toolOptions'])) : array();
156 0 : $this->userSignupSettings = (isset($toolDataArray['userSignupSettings']) ? $toolDataArray['userSignupSettings'] : 0) ®ISTRATION_TYPE_MASK;
157 0 : $this->registrationRequired = !((((isset($toolDataArray['userSignupSettings']) ? $toolDataArray['userSignupSettings'] : 0) ®ISTRATION_TYPE_MASK) == SIGNUP_AUTOMATICLY) OR (((isset($toolDataArray['userSignupSettings']) ? $toolDataArray['userSignupSettings'] : 0) ®ISTRATION_TYPE_MASK) == SIGNUP_MANUALY));
158 0 : $this->userRegisterStatus = null;
159 0 : $this->tools['xpweb 3.0'] = new XPWebInfo($this->id, "XPWeb-small-over.gif");
160 0 : $this->tools['xpweb 3.0']->setToolOptions($this->toolOptions);
161 0 : $this->tools['mantis 1.0'] = new MantisInfo($this->id, "mantis_logo_button.gif");
162 0 : $this->tools['mantis 1.0']->setToolOptions($this->toolOptions);
163 0 : $this->tools['mediawiki 1.5'] = new MediaWikiInfo($this->id, "poweredby_mediawiki_88x31.png");
164 0 : $this->tools['mediawiki 1.5']->setToolOptions($this->toolOptions);
165 0 : $this->tools['chat'] = new ChatInfo($this->id, "jabber_logo.png");
166 0 : $this->tools['chat']->setToolOptions($this->toolOptions);
167 0 : $this->tools['wordpress 2'] = new WordPressInfo($this->id, "wordpress_logo.png");
168 0 : $this->tools['wordpress 2']->setToolOptions($this->toolOptions);
169 : //$this->tools['eStudyLink'] = new EstudyInfo($this->id);
170 :
171 0 : }
172 : /**
173 : *
174 : * @access public
175 : * @param boolean $isRegisterLink
176 : * @return void
177 : */
178 : public function echoLink($isRegisterLink = false) {
179 0 : $string = "<a href='%s?ID=%s' title='%s' %s>";
180 0 : $string = sprintf($string, PATH_TO_ROOT.SCRIPT_NAME, $this->id, $this->description, "%s");
181 0 : if ($this->showInOwnWindow) {
182 0 : if (isset($this->tools[$this->type]) && is_object($this->tools[$this->type])) {
183 0 : if (is_null($this->tools[$this->type]->getUserLoginData($_SESSION['userid']))) {
184 0 : printf($string, "");
185 0 : } else {
186 0 : printf($string, "target='_blank'");
187 : }
188 0 : } else {
189 0 : printf($string, "target='_blank'");
190 : }
191 0 : } else {
192 0 : printf($string, "");
193 : }
194 0 : if ($this->logo != "") {
195 0 : $string = "<img src='%s' alt='%s' title='%s' />";
196 0 : printf($string, $this->logo, $this->name, $this->name);
197 0 : } elseif (isset($this->tools[$this->type])) {
198 0 : echo $this->tools[$this->type]->getImageLink($this->name);
199 0 : } else {
200 0 : echo $this->name;
201 : }
202 0 : echo "</a>";
203 0 : }
204 : /**
205 : * Gibt die Beschreibung des Tools aus.
206 : * @access public
207 : * @return void
208 : */
209 : public function echoDescription() {
210 0 : echo $this->description;
211 0 : }
212 : /**
213 : * Gibt die ID des Tools zurück.
214 : * @access public
215 : * @return void
216 : */
217 : public function getID() {
218 0 : return $this->id;
219 : }
220 : /**
221 : *
222 : * @access public
223 : * @return integer
224 : */
225 : public function getUserSignupSettings() {
226 0 : return $this->userSignupSettings;
227 : }
228 : /**
229 : *
230 : * @access public
231 : * @return boolean
232 : */
233 : public function isRegistrationRequired() {
234 0 : return $this->registrationRequired;
235 : }
236 : /**
237 : *
238 : * @access public
239 : * @return
240 : */
241 : public function getUserRegisterStatus($userID, $courseID) {
242 0 : global $db, $settings;
243 0 : if (is_null($this->userRegisterStatus)) {
244 0 : $query = "SELECT status FROM %set_signuprequests WHERE ";
245 0 : $query.= "toolID='%s' AND userID='%s' AND courseID='%s'";
246 0 : $query = sprintf($query, $settings['dbPrefix'], $this->id, Data::toMysql($userID), Data::toMysql($courseID));
247 0 : $this->userRegisterStatus = $db->get_var($query);
248 0 : }
249 0 : return $this->userRegisterStatus;
250 : }
251 : /**
252 : *
253 : * @access public
254 : * @return void
255 : */
256 : public function echoPage() {
257 0 : $result = $this->logonUserToTool($_SESSION['userid']);
258 0 : if ($result === true) {
259 0 : $this->echoPageContent();
260 0 : } else {
261 : switch ($result) {
262 0 : case 1:
263 0 : $this->echoNoLoginData();
264 0 : break;
265 :
266 0 : case 2:
267 0 : $this->echoCantInsertNewUserMessage();
268 0 : break;
269 : }
270 : }
271 0 : }
272 : /**
273 : *
274 : * @access public
275 : * @param integer $userID
276 : * @return mixed
277 : */
278 : public function logonUserToTool($userID) {
279 0 : if (isset($this->tools[$this->type])) {
280 0 : $toolinfo = $this->tools[$this->type];
281 0 : if (is_null($toolinfo->getUserLoginData($userID))) {
282 0 : return 1;
283 : }
284 0 : if (!$toolinfo->logon($userID)) {
285 0 : return 2;
286 : }
287 0 : }
288 0 : return true;
289 : }
290 : /**
291 : *
292 : * @accesspublic
293 : * @return void
294 : */
295 : public function echoPageContent() {
296 0 : $this->handleToolOptions(OPTIONS_EVENT_SHOW_PAGE);
297 0 : if ($this->showInOwnWindow) {
298 0 : header("Location:".$this->url);
299 0 : } else {
300 0 : echo "<iframe src='".$this->url."' width='100%' height='600'frameborder='0'>\n";
301 0 : echo "<p>Leider unterstützt Ihr Browser keine IFrames. Hier der direkte Link zu ".$this->name.":<br />\n";
302 0 : echo "<a href='".$this->url."'>".$this->url."</a></p>\n";
303 0 : echo "</iframe>\n";
304 : }
305 0 : }
306 : /**
307 : *
308 : * @access public
309 : * @param string $oldLogin - Der alte Loginname.
310 : * @param string $newLogin - Der neue Loginname.
311 : * @param string $passwprd - Das Passwort.
312 : * @return
313 : */
314 : public function updateLogin($oldLogin, $newLogin, $password) {
315 0 : if (isset($this->tools[$this->type])) {
316 0 : $toolinfo = $this->tools[$this->type];
317 0 : return $toolinfo->update($oldLogin, $newLogin, $password);
318 : } else {
319 0 : return null;
320 : }
321 : }
322 : /**
323 : *
324 : * @access public
325 : * @return void
326 : */
327 : public function echoNoLoginData() {
328 0 : echo "<h2 class='error'>Fehler: Keine Logindaten angegeben!</h2>\n";
329 0 : echo "<p>Um Zugriff zu diesem externen Werkzeug zu erhalten, ";
330 0 : echo "müssen Sie Ihre Logindaten, bestehend aus Benutzername ";
331 0 : echo "und Passwort, setzen! Aus Sicherheits- und Kompatibilitätsgründen ";
332 0 : echo "unterscheiden sich diese von Ihren eStudy-Zugangsdaten.</p>\n";
333 0 : echo "<p>";
334 0 : $link = "[<a href='%s?action=showLoginData' title='Logindaten anlegen'>Logindaten anlegen</a>]";
335 0 : printf($link, PATH_TO_ROOT."externaltools/externaltools.settings.php");
336 0 : echo "</p>\n";
337 0 : }
338 : /**
339 : *
340 : * @access public
341 : * @return void
342 : */
343 : public function echoCantInsertNewUserMessage() {
344 0 : echo "<table width='100%'>";
345 0 : $errorMessage = "<b>Fehler:</b> Sie konnten nicht automatisch angemeldet werden.<br />\n";
346 0 : $errorMessage.= "Bitte prüfen Sie, ob Ihre Login-Einstellungen für externe Werkzeuge korrekt sind.";
347 0 : Output::errorMessage($errorMessage);
348 0 : echo "</table>";
349 0 : }
350 : /**
351 : *
352 : * @access public
353 : * @param integer $event
354 : * @return void
355 : */
356 : public function handleToolOptions($event) {
357 0 : if (isset($this->tools[$this->type])) {
358 0 : $toolinfo = $this->tools[$this->type];
359 0 : $toolinfo->setToolOptions($this->toolOptions);
360 0 : $toolinfo->handleToolOptions($event);
361 0 : }
362 0 : }
363 : /**
364 : *
365 : * @access public
366 : * @param mixed $hiddenVars
367 : * @return mixed
368 : */
369 : public function showOptionsDialog($hiddenVars) {
370 0 : if (isset($this->tools[$this->type])) {
371 0 : $toolinfo = $this->tools[$this->type];
372 0 : $toolinfo->setToolOptions($this->toolOptions);
373 0 : $result = $toolinfo->showOptionsDialog($hiddenVars);
374 0 : if (is_bool($result)) {
375 0 : return $result;
376 : } else {
377 0 : $this->saveToolOptions($result);
378 : }
379 0 : }
380 0 : return true;
381 : }
382 : /**
383 : *
384 : * @access public
385 : * @param mixed $options
386 : * @return void
387 : */
388 : public function saveToolOptions($options) {
389 0 : global $db, $settings;
390 0 : $query = "UPDATE %set_tools SET toolOptions='%s' WHERE toolID='%s' AND courseID='%s'";
391 0 : $query = sprintf($query, $settings['dbPrefix'], serialize($options), $this->id, $_SESSION['course']);
392 0 : $db->query($query);
393 0 : }
394 : }
|